package telas;

import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import modelo.Cliente;
import modelo.Plano;

public class TelaDependente {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="93,78"
	private JPanel jContentPane = null;
	private JLabel jLabel = null;
	private JComboBox jComboBox = null;
	private JLabel jLabel1 = null;
	private JTextField jTextField = null;
	private JLabel jLabel2 = null;
	private JTextField jTextField1 = null;
	private JLabel jLabel3 = null;
	private JComboBox jComboBox1 = null;
	private JPanel jPanel = null;
	private JLabel jLabel4 = null;
	private JTextField jTextField2 = null;
	private JButton jButtonPrimeiro = null;
	private JButton jButtonAnterior = null;
	private JButton jButtonProximo = null;
	private JButton jButtonUltimo = null;
	private JButton jButtonNovo = null;
	private JButton jButtonAlterar = null;
	private JButton jButtonExcluir = null;
	private JButton jButtonConsultar = null;
	private JButton jButtonSair = null;
	private JButton jButtonConfirmar = null;
	private JButton jButtonCancelar = null;
	private JLabel jLabelCPF = null;
	private JTextField jTextFieldCPF = null;
	private JButton jButtonPesquisar = null;
	private JButton jButtonCadastrar = null;
	/**
	 * This method initializes jFrame	
	 * 	
	 * @return javax.swing.JFrame	
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setTitle("Tela Dependentes");
			jFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/logo.jpg")));
			jFrame.setVisible(true);
			jFrame.setResizable(false);
			jFrame.setBounds(new Rectangle(200, 200, 575, 350));
			jFrame.setContentPane(getJContentPane());
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabelCPF = new JLabel();
			jLabelCPF.setBounds(new Rectangle(10, 120, 30, 25));
			jLabelCPF.setText("CPF:");
			jLabel4 = new JLabel();
			jLabel4.setBounds(new Rectangle(10, 90, 114, 25));
			jLabel4.setText("Nome Dependente:");
			jLabel3 = new JLabel();
			jLabel3.setBounds(new Rectangle(290, 150, 42, 25));
			jLabel3.setText("Plano:");
			jLabel2 = new JLabel();
			jLabel2.setBounds(new Rectangle(10, 180, 108, 25));
			jLabel2.setText("Grau Parentesco:");
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(10, 150, 75, 25));
			jLabel1.setText("Data Nasc.:");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(10, 210, 60, 25));
			jLabel.setText("Cliente:");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJComboBox(), null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(getJTextField1(), null);
			jContentPane.add(jLabel3, null);
			jContentPane.add(getJComboBox1(), null);
			jContentPane.add(jLabel4, null);
			jContentPane.add(getJTextField2(), null);
			jContentPane.add(getJButtonPrimeiro(), null);
			jContentPane.add(getJButtonAnterior(), null);
			jContentPane.add(getJButtonProximo(), null);
			jContentPane.add(getJButtonUltimo(), null);
			jContentPane.add(getJButtonNovo(), null);
			jContentPane.add(getJButtonAlterar(), null);
			jContentPane.add(getJButtonExcluir(), null);
			jContentPane.add(getJButtonConsultar(), null);
			jContentPane.add(getJButtonSair(), null);
			jContentPane.add(getJButtonConfirmar(), null);
			jContentPane.add(getJButtonCancelar(), null);
			jContentPane.add(jLabelCPF, null);
			jContentPane.add(getJTextFieldCPF(), null);
			jContentPane.add(getJButtonPesquisar(), null);
			jContentPane.add(getJButtonCadastrar(), null);
			
		}
		return jContentPane;
	}

	/**
	 * This method initializes jComboBox	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox() {
		if (jComboBox == null) {
			jComboBox = new JComboBox();
			jComboBox.setBounds(new Rectangle(130, 210, 390, 25));
			jComboBox.addItem(" ");
			jComboBox.setEnabled(false);
		}
		return jComboBox;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(130, 150, 125, 25));
			jTextField.setEnabled(false);
		}
		return jTextField;
	}

	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setBounds(new Rectangle(130, 180, 150, 25));
			jTextField1.setEnabled(false);
		}
		return jTextField1;
	}

	/**
	 * This method initializes jComboBox1	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox();
			jComboBox1.setBounds(new Rectangle(335, 151, 183, 25));
			jComboBox1.addItem(" ");
			jComboBox1.setEnabled(false);
			
		}
		return jComboBox1;
	}

	private JButton getJButtonPrimeiro() {
		
		//	ImageIcon img = new ImageIcon("image/im-fir.gif");
			
			if (jButtonPrimeiro == null) {
				jButtonPrimeiro = new JButton();
				jButtonPrimeiro.setBounds(new Rectangle(25, 16, 35, 33));	
				jButtonPrimeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-fir.jpg")));
			//	jButtonPrimeiro.setSize(new Dimension(35, 33));
			//	jButtonPrimeiro.setLocation(new Point(22, 16));
			}
			return jButtonPrimeiro;
		}

		/**
		 * This method initializes jButtonAnterior	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonAnterior() {
			if (jButtonAnterior == null) {
				jButtonAnterior = new JButton();
				jButtonAnterior.setBounds(new Rectangle(65, 16, 35, 33));		
				jButtonAnterior.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-ante.jpg")));
			//  jButtonAnterior.setIconImage("C:\Java\Workspace\ProjFinal\toolbar\im-fir.bmp");
			//	jButtonAnterior.setLocation(new Point(85, 17));
			//	jButtonAnterior.setSize(new Dimension(35, 33));
			}
			return jButtonAnterior;
		}

		/**
		 * This method initializes jButtonProximo	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonProximo() {
			if (jButtonProximo == null) {
				jButtonProximo = new JButton();
				jButtonProximo.setBounds( new Rectangle(105, 16, 35, 33));
				jButtonProximo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-prox.jpg")));
			//	jButtonProximo.setSize(new Dimension(35, 33));
			}
			return jButtonProximo;
		}

		/**
		 * This method initializes jButtonUltimo	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonUltimo() {
			if (jButtonUltimo == null) {
				jButtonUltimo = new JButton();
				jButtonUltimo.setBounds(new Rectangle(145, 16, 35, 33));
				jButtonUltimo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-las.jpg")));			
			}
			return jButtonUltimo;
		}

		/**
		 * This method initializes jButtonNovo	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonNovo() {
			if (jButtonNovo == null) {
				jButtonNovo = new JButton();
				jButtonNovo.setBounds(new Rectangle(200, 16, 35, 33));
				jButtonNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-add.jpg")));
			}
			return jButtonNovo;
		}

		/**
		 * This method initializes jButtonAlterar	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonAlterar() {
			if (jButtonAlterar == null) {
				jButtonAlterar = new JButton();
				jButtonAlterar.setBounds(new Rectangle(240, 16, 35, 33));
				jButtonAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-mod.jpg")));
			}
			return jButtonAlterar;
		}

		/**
		 * This method initializes jButtonExcluir	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonExcluir() {
			if (jButtonExcluir == null) {
				jButtonExcluir = new JButton();
				jButtonExcluir.setBounds(new Rectangle(280, 16, 35, 33));
				jButtonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-era.jpg")));
			}
			return jButtonExcluir;
		}

		/**
		 * This method initializes jButtonConsultar	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonConsultar() {
			if (jButtonConsultar == null) {
				jButtonConsultar = new JButton();
				jButtonConsultar.setBounds(new Rectangle(320, 16, 35, 33));
				jButtonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-pid.jpg")));
			//	jButtonConsultar.setSize(new Dimension(35, 33));
			}
			return jButtonConsultar;
		}

		/**
		 * This method initializes jButtonSair	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonSair() {
			if (jButtonSair == null) {
				jButtonSair = new JButton();
				jButtonSair.setBounds(new Rectangle(500, 16, 35, 33));
				jButtonSair.setName("Sair");
				jButtonSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/im-exi.jpg")));
			}
			return jButtonSair;
		}

		/**
		 * This method initializes jButtonConfirmar	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonConfirmar() {
			if (jButtonConfirmar == null) {
				jButtonConfirmar = new JButton();
				jButtonConfirmar.setBounds(new Rectangle(390, 16, 35, 33));
				jButtonConfirmar.setIcon(new ImageIcon(getClass().getResource("/image/im-cq.jpg")));
				jButtonConfirmar.setVisible(false);
			}
			return jButtonConfirmar;
		}

		/**
		 * This method initializes jButtonCancelar	
		 * 	
		 * @return javax.swing.JButton	
		 */
		private JButton getJButtonCancelar() {
			if (jButtonCancelar == null) {
				jButtonCancelar = new JButton();
				jButtonCancelar.setBounds(new Rectangle(430, 16, 35, 33));
				jButtonCancelar.setIcon(new ImageIcon(getClass().getResource("/image/im-can.jpg")));
				jButtonCancelar.setVisible(false);
			}
			return jButtonCancelar;
		}
	
	
	public TelaDependente(){
		getJFrame();
	}
	public void mostraMensagem(String msg)
	{
		JOptionPane.showMessageDialog(null,msg);
	}
	public void fecharTela(){
		jFrame.dispose();
	}
	public void limpaTela(){
		jComboBox.setSelectedItem(" ");
		jTextField.setText(" ");
		jTextField1.setText(" ");
		jTextField2.setText(" ");
		jComboBox1.setSelectedItem(" ");
		
		
	}
	public void addDependenteListener(ActionListener l)
	{
		jButtonPrimeiro.addActionListener(l);
		jButtonAnterior.addActionListener(l);
		jButtonProximo.addActionListener(l);
		jButtonUltimo.addActionListener(l);
		jButtonNovo.addActionListener(l);
		jButtonAlterar.addActionListener(l);
		jButtonExcluir.addActionListener(l);
		jButtonConsultar.addActionListener(l);
		jButtonConfirmar.addActionListener(l);
		jButtonCancelar.addActionListener(l);
		jButtonSair.addActionListener(l);	
		jButtonPesquisar.addActionListener(l);
		jButtonCadastrar.addActionListener(l);
		
		jButtonPrimeiro.setActionCommand("Primeiro");
		jButtonAnterior.setActionCommand("Anterior");
		jButtonProximo.setActionCommand("Proximo");
		jButtonUltimo.setActionCommand("Ultimo");
		jButtonNovo.setActionCommand("Novo");
		jButtonAlterar.setActionCommand("Alterar");
		jButtonExcluir.setActionCommand("Excluir");
		jButtonConsultar.setActionCommand("Consultar");
		jButtonConfirmar.setActionCommand("Confirmar");
		jButtonCancelar.setActionCommand("Cancelar");
		jButtonSair.setActionCommand("Sair");	
		jButtonPesquisar.setActionCommand("Pesquisar");
		jButtonCadastrar.setActionCommand("Cadastrar");
		
		
	}
	public String getNomecli()
	{
		return (String) jComboBox.getSelectedItem();
	}
	public String getNomedepen()
	{
		return jTextField2.getText();
	}
	
	public String getDatanasc()
	{
		return jTextField.getText();
	}
	public String getGrau()
	{
		return jTextField1.getText();
	}
	public String getPlano()
	{
		return (String) jComboBox1.getSelectedItem();
	}
	public void setNomecli(String nomecli){
		jComboBox.setSelectedItem(nomecli);
	}
	public void setNomedepen(String nomedepen) {
		jTextField2.setText(nomedepen);
	}
	public void setDatanasc(String datanasc) {
		jTextField.setText(datanasc);
	}
	public void setGrau(String grau) {
		jTextField1.setText(grau);
	}
	public void setPlano(String plano){
		jComboBox1.setSelectedItem(plano);
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	public void preencheComboClientes(ArrayList clientes){
		if(clientes!=null){
			for(int i=0;i<clientes.size();i++){
				Cliente c=(Cliente)clientes.get(i);
				jComboBox.addItem(c.getNome_cli());
			}
		}
	}
	public void preencheComboPlanos(ArrayList planos){
		if(planos!=null){
			for(int i=0;i<planos.size();i++){
				Plano p=(Plano)planos.get(i);
				jComboBox1.addItem(p.getNome_plano());				
			}			
		}	
		
	}

	/**
	 * This method initializes jTextField2	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField2() {
		if (jTextField2 == null) {
			jTextField2 = new JTextField();
			jTextField2.setBounds(new Rectangle(130, 90, 350, 25));
			jTextField2.setEnabled(false);
		}
		return jTextField2;
	}

	/**
	 * This method initializes jTextFieldCPF	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldCPF() {
		if (jTextFieldCPF == null) {
			jTextFieldCPF = new JTextField();
			jTextFieldCPF.setBounds(new Rectangle(130, 120, 175, 25));
			jTextFieldCPF.setEnabled(false);
		}
		return jTextFieldCPF;
	}
	
	private JButton getJButtonPesquisar() {
		if (jButtonPesquisar == null) {
			jButtonPesquisar = new JButton();
			jButtonPesquisar.setBounds(new Rectangle(500, 90, 25, 25));
			jButtonPesquisar.setIcon(new ImageIcon(getClass().getResource("/image/im-pid.jpg")));
			jButtonPesquisar.setVisible(false);
		}
		return jButtonPesquisar;
	}

	/**
	 * This method initializes jButtonCadastrar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonCadastrar() {
		if (jButtonCadastrar == null) {
			jButtonCadastrar = new JButton();
			jButtonCadastrar.setBounds(new Rectangle(389, 16, 35, 33));
			jButtonCadastrar.setIcon(new ImageIcon(getClass().getResource("/image/im-cq.jpg")));
			jButtonCadastrar.setVisible(false);
		}
		return jButtonCadastrar;
	}
	
	public void preenchePrimeiroRegistro(){
		jButtonPrimeiro.doClick();		
	}
	
	public void habilitaCamposAlterar(){
		
		//mostraMensagem("habilitaConfirmar");
		
		jTextField.enable(false);
		jTextField1.enable(true);
		jTextField2.enable(true);
		jTextFieldCPF.enable(true);
		jComboBox.enable(true);
		jComboBox1.enable(true);
		
		jButtonConfirmar.setVisible(true);
		jButtonCancelar.setVisible(true);
		
		jButtonPrimeiro.setVisible(false);
		jButtonAnterior.setVisible(false);
		jButtonProximo.setVisible(false);
		jButtonUltimo.setVisible(false);
		
		jButtonNovo.setVisible(false);
		jButtonAlterar.setVisible(false);
		jButtonExcluir.setVisible(false);
		jButtonConsultar.setVisible(false);
		
		jButtonPesquisar.setVisible(false);
		
		jTextField.grabFocus();
		
		// jButtonConfirmar.setIcon(new ImageIcon(getClass().getResource("/image/im-cq.jpg")));
		// jButtonCancelar.setIcon(new ImageIcon(getClass().getResource("/image/im-can.jpg")));
		
	}
	
public void habilitaCamposCadastrar(){
		
		// mostraMensagem("habilitaCadastrar");
		
		jTextField.enable(true);
		jTextField1.enable(true);
		jTextField2.enable(true);
		jTextFieldCPF.enable(true);
		jComboBox.enable(true);
		jComboBox1.enable(true);
		
		jButtonCadastrar.setVisible(true);
		jButtonCancelar.setVisible(true);
		
		jButtonPrimeiro.setVisible(false);
		jButtonAnterior.setVisible(false);
		jButtonProximo.setVisible(false);
		jButtonUltimo.setVisible(false);
		
		jButtonNovo.setVisible(false);
		jButtonAlterar.setVisible(false);
		jButtonExcluir.setVisible(false);
		jButtonConsultar.setVisible(false);
		
		jButtonPesquisar.setVisible(false);
		
		jTextField.grabFocus();
		
		// jButtonConfirmar.setIcon(new ImageIcon(getClass().getResource("/image/im-cq.jpg")));
		// jButtonCancelar.setIcon(new ImageIcon(getClass().getResource("/image/im-can.jpg")));
		
	}
	
	public void desabilitaCampos(){
		
		// mostraMensagem("desabilita");
		
		jTextField.enable(false);
		jTextField1.enable(false);
		jTextField2.enable(false);
		jTextFieldCPF.enable(false);
		jComboBox.enable(false);
		jComboBox1.enable(false);
		
		jButtonPrimeiro.setVisible(true);
		jButtonAnterior.setVisible(true);
		jButtonProximo.setVisible(true);
		jButtonUltimo.setVisible(true);
		
		jButtonNovo.setVisible(true);
		jButtonAlterar.setVisible(true);
		jButtonExcluir.setVisible(true);
		jButtonConsultar.setVisible(true);	
		
		jButtonConfirmar.setVisible(false);
		jButtonCadastrar.setVisible(false);
		jButtonCancelar.setVisible(false);
		
		jButtonPesquisar.setVisible(false);
		
	}
	
	public void habilitaPesquisa(){		
		jTextField.enable(false);
		jTextField1.enable(false);
		jTextField2.enable(true);
		jTextFieldCPF.enable(false);
		jComboBox.enable(false);
		jComboBox1.enable(false);
		
		
		
		jButtonPesquisar.setVisible(true);
		jButtonCancelar.setVisible(true);
		
		jButtonPrimeiro.setVisible(false);
		jButtonAnterior.setVisible(false);
		jButtonProximo.setVisible(false);
		jButtonUltimo.setVisible(false);
		
		jButtonNovo.setVisible(false);
		jButtonAlterar.setVisible(false);
		jButtonExcluir.setVisible(false);
		jButtonConsultar.setVisible(false);
		
		jTextField.grabFocus();		
		
		
	}

		
	 
	

}
